import re


def get_priority(value_expr_str):
    value_expr_str = re.sub(" ", "", value_expr_str)
    data_list = []
    temp = ""
    symbol = ['(', ')', '+', '-', '*', '/']
    for i in value_expr_str:
        if i not in symbol:
            temp += i
        else:
            if (i == '-' and temp == "") or (i == "-" and temp[-1] in symbol):
                temp += '-'
                continue
            if temp != "":
                data_list.append(temp)
                temp = ""
            data_list.append(i)
    if temp != "":
        data_list.append(temp)
    return priority_order(data_list)


def compute(arr, value_expr_arr):
    for i, j in enumerate(value_expr_arr):
        if j == "*" or j == "/":
            arr.append([value_expr_arr[i - 1], value_expr_arr[i], value_expr_arr[i + 1]])
            value_expr_arr[i - 1] = ""
            value_expr_arr[i] = ""
            value_expr_arr[i + 1] = '$' + str(len(arr) - 1)
    value_expr_arr = [x for x in value_expr_arr if x != '']
    for i, j in enumerate(value_expr_arr):
        if j == "+" or j == "-":
            arr.append([value_expr_arr[i - 1], value_expr_arr[i], value_expr_arr[i + 1]])
            value_expr_arr[i + 1] = '$' + str(len(arr) - 1)


def priority_order(value_expr_arr):
    arr = []
    if "(" in value_expr_arr:
        while 1:
            if ")" in value_expr_arr:
                b = value_expr_arr.index(")")
                for i in range(b, -1, -1):
                    if value_expr_arr[i] == "(":
                        new_list = value_expr_arr[i + 1:b]
                        if len(new_list) > 3:
                            compute(arr, new_list)
                            temp = '$' + str(len(arr) - 1)
                        else:
                            temp = '$' + str(len(arr))
                            arr.append(new_list)
                        del (value_expr_arr[i:b + 1])
                        value_expr_arr.insert(i, temp)
                        break
            else:
                compute(arr, value_expr_arr) if len(value_expr_arr) > 3 else arr.append(value_expr_arr)
                return arr
    else:
        compute(arr, value_expr_arr) if len(value_expr_arr) > 3 else arr.append(value_expr_arr)
        return arr
